package com.filesystem.file.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.filesystem.file.entity.Files;
import com.filesystem.file.service.impl.FileServiceImpl;
import com.filesystem.utils.ResultUtil;
import com.filesystem.utils.Results;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author JayZhou
 * @since 2021-06-10
 */
@RestController
@RequestMapping("/files")
public class FileController {

    @Autowired
    FileServiceImpl fileService;


    /**
     * 查询所有
     * @return 查询所有
     */
    @RequestMapping("/userListFile")
    public Results userListFile(
            @RequestParam("page") int page,
            @RequestParam("limit") int limit
    ){
        //获取登录名
        Subject subject = SecurityUtils.getSubject();
        //(String) subject.getPrincipal()  这个是得到用户名后转了String类型
        Page<Files> selectuser = fileService.selectuser(page, limit, (String) subject.getPrincipal());
        long total = selectuser.getTotal();
        List<Files> data = selectuser.getRecords();
        System.out.println("用户名------------:"+(String) subject.getPrincipal());
        System.out.println("total---------------:"+total);
        System.out.println("data---------------:"+data);
        return ResultUtil.success(Math.toIntExact(total),data);
    }

}
